import java.util.*;
import java.util.ArrayList;

class MyStack{
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[5];
    }

    public void push(int val){
        if (isFull()){
            this.elem = Arrays.copyOf(this.elem,2*elem.length);
        }
        this.elem[usedSize] = val;
        usedSize++;

    }

    public int pop(){
        if (isEmpty()){
            throw new RuntimeException();
        }
        int OldVal = elem[usedSize-1];
        usedSize--;
        return OldVal;
    }

    public int peek(){
        if (isEmpty()){
            throw new RuntimeException();
        }
        int OldVal = elem[usedSize-1];
        return OldVal;
    }

    public boolean isFull(){
        return this.usedSize == this.elem.length;
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }

}

 class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++){
            stack.push(pushA[i]);
            while (j < popA.length && !stack.empty() && stack.peek() == popA[j]){
                stack.pop();
                j++;
            }
        }
        return stack.empty();


    }
}
class Board {
    public boolean checkWon(int[][] board) {
        // write code here
        int n = board.length;
        int sum = 0;
        int i = 0;
        int j = 0;
        for (i = 0; i < n; i++){
            sum = 0;
            for (j = 0; j < n; j++){
                sum += board[i][j];
            }
            if (sum == n){
                return true;
            }
        }

        for (i = 0; i < n; i++){
            sum = 0;
            for (j = 0; j < n; j++){
                sum += board[j][i];
            }
            if (sum == n){
                return true;
            }
        }

        sum = 0;
        for (i = 0; i < n;i++){
            sum += board[i][i];
            if (sum == n){
                return true;
            }
        }

        sum = 0;
        for (i = 0; i < n;i++){
            sum += board[i][n-1-i];
            if (sum == n){
                return true;
            }
        }
        return false;
    }
}
public class Test {
}
